package org.mine.design.factory.service.factory;

import org.mine.design.factory.enums.DemoFactoryEnum;
import org.mine.design.factory.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DemoFactory {

    @Autowired
    private List<DemoService> demoServices;

    public DemoService get(DemoFactoryEnum condition) {
        return demoServices.stream()
                .filter(service -> service.getDemoFactoryEnum() == condition)
                .findFirst()
                .orElseThrow(() -> new RuntimeException("未找到匹配的实现类..."));
    }
}
